package com.yanqu.road.server.cmd.grandchild.born;

import com.yanqu.road.entity.grandchild.GrandChildData;
import com.yanqu.road.pb.grandchild.GrandChildProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.grandson.GrandChildModule;
import com.yanqu.road.server.manger.config.grandchild.GrandChildConfigMgr;
import com.yanqu.road.server.pb.GrandChildPb;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

import java.util.List;
import java.util.Set;

@Cmd(code = GameProtocol.S_GRANDSON_TALENT_PREVIEW,desc = "天赋预览")
public class PreviewGrandChildTalentCmd extends AbstractCommand {
    private List<Integer> talentList;
    private String id;
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        GrandChildProto.TalentPreviewReqMsg req = GrandChildProto.TalentPreviewReqMsg.parseFrom(packet.getBytes());
        id = req.getId();
        talentList = req.getTalentIdList();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        GrandChildData grandChild = player.getModule(GrandChildModule.class).getGrandChild(id);
        GrandChildData clone = grandChild.clone();
        clone.setTalentList(talentList);

        Set<Integer> activeList = GrandChildConfigMgr.previewActiveTalentList(clone,talentList);
        GrandChildConfigMgr.grandChildBorn(player, clone,false);

        GrandChildProto.TalentPreviewRespMsg.Builder resp = GrandChildProto.TalentPreviewRespMsg.newBuilder();
        GrandChildProto.GrandChildMsg.Builder builder = GrandChildPb.parseGrandChildMsg(clone);
        resp.setGrandChild(builder);
        resp.setRet(0);
        resp.addAllActiveTalent(activeList);
        player.sendPacket(ClientProtocol.U_GRANDSON_TALENT_PREVIEW, resp);
    }



    @Override
    public void sendData(GamePlayer player) {

    }
}
